<template>
	<view class="uploads">
		<view class="w94 radius20 bgwhite mt20" style="padding: 24rpx;">
			<view class="" style="padding: 24rpx 0;">
				<text style="color: red;">*</text> 上传本人照片作为头像
			</view>
			<view class="w94 radius20 flex"
				style="background-color: #F8F8F8; height: 400rpx; justify-content: center;align-items: center;">
				<image src="@/static/login/2.png" mode="" style="width: 100rpx;height: 100rpx;" v-if="!src"
					@click="upAvater"></image>
				<image :src="src" mode="" style="width: 300rpx;height: 300rpx;border-radius: 50%;" v-else>
				</image>
			</view>
		</view>
		<view class="w94 radius20 bgwhite mt20" style="padding: 24rpx;">
			<view class="" style="padding: 24rpx 0;">
				<text style="color: red;">*</text> 上传工作时期照片
			</view>
			<view class="w94 radius20 flex"
				style="background-color: #F8F8F8; height: 400rpx; justify-content: center;align-items: center;"
				v-if="!srcList.length" @click="upLife">
				<image src="@/static/login/2.png" mode="" style="width: 100rpx;height: 100rpx;">
				</image>
			</view>
			<block v-else v-for="i in srcList" :key="i">
				<image :src="i" mode=""
					style="width: 100rpx;height: 100rpx;border-radius: 25rpx;margin-left: 20rpx;background-color: #F8F8F8;">
				</image>
			</block>
		</view>
		<view class=""
			style="box-shadow: 1px -5px 10px #ccc;position: absolute;bottom: 0;padding: 30rpx; background-color: #fff;display: flex;justify-content: center;width: 100%;">
			<view class=""
				style="width: 80%;height: 90rpx;border-radius: 90rpx;background-color: #CEEE5B;text-align: center;line-height: 2.5;"
				@click="submit">
				下一步
			</view>
		</view>
	</view>
</template>

<script>
	import {
		uploadFile,
		uploadFiles,
		profile
	} from '@/common/teacherReq';
	export default {
		data() {
			return {
				src: '',
				srcList: []
			}
		},
		computed: {
			info() {
				return uni.getStorageSync('info')
			}
		},
		methods: {
			upAvater() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						// console.log(res.tempFilePaths);
						this.src = res.tempFilePaths
						uploadFile({
							filePath: res.tempFilePaths[0],
						}).then(resp => {
							this.src = JSON.parse(resp[1].data).data.fullurl
							console.log('resp: ', this.src);
						}).catch(err => {
							uni.showToast({
								icon: 'error',
								title: '上传失败' + err
							})
						})
					}
				})
			},
			upLife() {
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						// console.log(JSON.stringify(res.tempFilePaths));
						this.srcList = res.tempFilePaths
						uploadFiles({
							filePaths: res.tempFilePaths
						}).then(resp => {
							this.srcList = resp.map(ite => ite.data.fullurl)
							console.log(this.srcList, 'resp---')
						}).catch(err => {
							uni.showToast({
								icon: 'error',
								title: '上传失败' + err
							})
						})
					}
				})
			},
			submit() {
				profile({
					username: this.info.username,
					nickname: this.info.nickname,
					avatar: this.src,
					rest_off: 1,
					contact: "",
					work_photo: this.srcList
				}).then(res => {
					console.log(res, 'res')
					this.toPage('/subpack/login/adress?type=1')
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uploads {
		position: relative;
		height: calc(100vh - 20rpx);
	}
</style>